package main

import "fmt"

// Player 定义玩家结构体
type Player struct {
	Name        string
	HealthPoint int // 血量
	Level       int // 等级
}

// NewPlayer Player构造函数
func NewPlayer(name string, healthPoint int, level int) *Player {
	return &Player{
		Name:        name,
		HealthPoint: healthPoint,
		Level:       level,
	}
}

// 针对Player的方法接收器
func (player *Player) attack(attacker *Player) {
	fmt.Println(player.Name + "向" + attacker.Name + "发起攻击!")
	attacker.attacked()
}

// 针对Player的方法接收器
func (player *Player) attacked() {
	fmt.Println(player.Name + "被攻击!")
	player.HealthPoint -= 10
}

func main() {
	// 定义两个玩家
	var player1 = NewPlayer("zhangsan", 100, 10)
	var player2 = NewPlayer("lisi", 100, 20)
	// 模拟player1向player2发起攻击
	player1.attack(player2)
	fmt.Println(*player1)
	fmt.Println(*player2)
}
